<?php
namespace Lib\Stack;
use Lib\Stack;
/**
 * 
 */
class StackStorage extends \ArrayObject{
    /**
     * Get stack  specified by $name from stack storage or creates it
     * @param String $name 
     * @return Lib\Stack
     */
    public function getStack($name){
        if(!$this->hasStack($name)){
            $this->offsetSet($name, new Stack($name));
        }
        return $this->offsetGet($name);
    }
    
    /**
     * Check existence of stack specified by $name in stack storage
     * @param string $name
     * @return bool
     */
    public function hasStack($name){
        if(!$this->offsetExists($name)) return false;
        return ($this->offsetGet($name) instanceof Stack);
    }
    
    public function setStack(Stack $stack){
        $this->offsetSet($stack->getName(), $stack);
    }
}